const Config = require('../config');
module.exports = (sequelize, Sequelize) => {
    return sequelize.define("pure_files",
        {
            id: {
                type: Sequelize.UUID,
                notNull: true,
                primaryKey: true,
                defaultValue: Sequelize.UUIDV4 // 或 DataTypes.UUIDV1
            },
            user_id: {
                type: Sequelize.STRING,
                comment: '上传用户',
            },
            path: {
                type: Sequelize.STRING,
                comment: '文件地址',
            },
            url:{
                type: Sequelize.VIRTUAL,
                get() {
                    return `${Config.baseURL}/api/public/v1/getFiles?id=${this.id}`
                }
            },
            // 下载
            download: {
                type: Sequelize.VIRTUAL,
                get() {
                    return `${Config.baseURL}/api/public/v1/getFiles/download?id=${this.id}`
                }
            },
            ext: {
                type: Sequelize.STRING,
                comment: '文件后缀',
            },
            name: {
                type: Sequelize.STRING,
                comment: '文件名称',
            },
            size: {
                type: Sequelize.STRING,
                comment: '文件大小',
            },
            content: {
                type: Sequelize.TEXT("long"),
                comment: '备注',
            },
            hash: {
                type: Sequelize.STRING,
                allowNull: false,
                unique: true,
                comment: '文件的哈希值'
            },
            mimetype: {
                type: Sequelize.STRING,
                comment: '文件类型',
            },
        }, {
        comment: '系统附件',
        updatedAt: false,
    });
};
